Jump to content

[SOLVED] Code not outputting properly


macattack

Recommended Posts

I have the following code

 

require("mysql.php");
$con = mysql_connect(PATH,USERNAME,PASSWORD);
$database = mysql_select_db(DATABASE);
if(!$database)
{
header('Location: login.php?database=no');
}
else
{
$surname1 = strtoupper($_POST['surname']);
$name1 = strtoupper($_POST['name']);
$surname = mysql_real_escape_string($surname1);
$name = mysql_real_escape_string($name1);
$query = mysql_query("SELECT * FROM Electors WHERE Surname='".$surname."' AND Name='".$name."';");
if(mysql_num_rows($query) >= 2)
{
	echo "Who do you mean?<br/>
			<table border='1'><tr><th>Name</th><th>Surname</th><th>Address</th><th>Submit</th></tr>";
	while($row=mysql_fetch_assoc($query))
	{
		echo "<tr><form action='index.php?task=name&vid=".$row['V_ID']."' method='post'>
			<td>".$row['Name']."</td><td>".$row['Surname']."</td><td>";
		if($row['unit'] != ' ')
		{
			echo $row['unit']."-";
		}
		echo $row['number']." ".$row['street']." ".$row['streettype']."</td>";
		echo "<td><input type='submit'></td></tr>";
	}
}
if(mysql_num_rows($query) == '1')
{
	$row = mysql_fetch_assoc($query));
	header("Location: index.php?task=name&vid=".$row['V_ID']);
}
else
{
	header("Location: index.php?task=name&exist=no");
}
}

 

and for some reason, it won't execute past the first if(mysql_num_rows($query)) clause.

 

If someone may know why (I bet it's a minor oversight that an hour or so of trying things hasn't caught) your help is greatly appreciated!

 

Basically, I want to see if the same name is in the list more than once. If it is, the person should have the option to confirm who they are searching for, if it's there once, it should redirect automatically, and if it's not there at all, redirect and give an error message.

Link to comment
https://forums.phpfreaks.com/topic/158435-solved-code-not-outputting-properly/
Share on other sites

change:

$con = mysql_connect(PATH,USERNAME,PASSWORD);
$database = mysql_select_db(DATABASE);
if(!$database)
{
   header('Location: login.php?database=no');
}

to

$con = mysql_connect(PATH,USERNAME,PASSWORD);
$database = mysql_select_db(DATABASE,$con);
if(!$database)
{
   header('Location: login.php?database=no');
}

I have made a few changes to the code, but still no luck.

 


require("mysql.php");
$con = mysql_connect(PATH,USERNAME,PASSWORD);
$database = mysql_select_db(DATABASE);
if(!$database)
{
header('Location: login.php?database=no');
}
else
{
$surname1 = strtoupper($_POST['surname']);
$name1 = strtoupper($_POST['name']);
$surname = mysql_real_escape_string($surname1);
$name = mysql_real_escape_string($name1);
$query = mysql_query("SELECT * FROM Electors WHERE Surname='".$surname."' AND Name='".$name."';");
//echo mysql_num_rows($query);

if(mysql_num_rows($query) >= 2)
{
	echo "Who do you mean?<br/>
			<table border='1'><tr><th>Name</th><th>Surname</th><th>Address</th><th>Submit</th></tr>";
	while($row=mysql_fetch_assoc($query))
	{
		echo "<tr><form action='index.php?task=name&vid=".$row['V_ID']."' method='post'>
			<td>".$row['Name']."</td><td>".$row['Surname']."</td><td>";
		if($row['unit'] != ' ')
		{
			echo $row['unit']."-";
		}
		echo $row['number']." ".$row['street']." ".$row['streettype']."</td>";
		echo "<td><input type='submit'></td></form></tr>";
	}
		echo "</table>";
}
if(mysql_num_rows($query) == 1)
{
	echo "here";
	$row = mysql_fetch_assoc($query));
	header("Location: index.php?task=name&vid=".$row['V_ID']);
}
else
{
	header("Location: index.php?task=name&exist=no");
}

}

The line that is commented out was uncommented and it returned a 1. So yes, I'm sure the query itself works. It's all the stuff after that that won't work. It won't even return the 1 unless the entire part after (with the exception of the final curly brace) is commented out. If that part is left on, the page is blank.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.