Here is a little bit of the code that generates a number based on retrieving the largest number from the field Number. However when it inserts it in, the Number value is 0.

here is the code:

<?php 
SESSION_start(); 
include("dbcon.php"); 
dbcon(); 
$user = mysql_real_escape_string($_POST['user']); 
$content = mysql_real_escape_string($_POST['content']); 
$date = mysql_real_escape_string($_POST['date']); 
$user2 = str_replace(".", " ", $user);

$query = "SELECT MAX(Number) FROM wall";
$query_config = mysql_query($query) or die(mysql_error());
$query_results_Number = mysql_fetch_array($query_config);
$new_Number_value = $query_results_Number++ ;

mysql_query("INSERT INTO `wall` (`user`, `from`, `content`, `date`, `Number`) VALUES('$user', '$user2', '$content', '$date', '$new_Number_value')")  
or die(mysql_error());   

echo  "<h1>Your post was successful</h1>"; 
echo "This page will be re-directed back to your wall in 5 seconds"; 
header('Refresh: 5; url=yourwall.php'); 
?>

Recommended Answers

All 4 Replies

mysql_fetch_array returns an array, just a the name implies, so this statement:

$new_Number_value = $query_results_Number++;

is trying to increment an array?
You want some thing like this:

$new_Number_value = $query_results_Number["Number"]++;

thanks, but it still produces a value of 0.

Member Avatar for diafol

Do you really need this Number column? Your 'id' primary key should be enough and your order (for display) should be set to date (if datetime) or even on the primary key itself. Your output to screen could be given a number from a simple counter (e.g. $i) as you loop through a recordset.

ya i was just trying this for an experiment, but im using the id now...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.