lameS..!

0 Sid wadhwa · October 4, 2015
How to connect a database when there are multiple tables in a database ?

Post a Reply

Replies

Oldest  Newest  Rating
0 Sid wadhwa · October 5, 2015
mysql_connect('localhost','root','');
 mysql_select_db('a_database');
 
 if(isset($_GET['id'])){
  $id = $_GET['id'];
  $query_run = mysql_query("SELECT `email` FROM `users` WHERE `id`='".mysql_real_escape_string($id)."'");
  if(mysql_num_rows($query_run)>=1){
   $query_result = mysql_result($query_run, 0, 'email');
  }
  else{
   echo "ID not found.";
  }
 }
 else{
  $email = "No email address.";
 }
Problem in this code then tell me that
0 Casper Hollemans · October 5, 2015
There isn't really a problem, do you get a error?
The only thing I'd change just for beauty and laziness is:
if(mysql_num_rows($query_run)>0){

it spares you one char xD but it's the usual way.

:D
0 Sid wadhwa · October 5, 2015
haha ! watch tutorial number 156 to 160 of PHP ! then tell me r u getting any error ?
because if I comment this code everything else is going into its place.
0 Casper Hollemans · October 5, 2015
So you are getting a error?
I don't understand you properly. 
0 Sid wadhwa · October 5, 2015
I know this code is right and the code I have written before it is also right but don't know why I am getting error , so I am suggesting you to watch tutorial number 156 to 160 and tell me do you have any error ?
0 Casper Hollemans · October 6, 2015
mhhh okay, but it'd be helpful if I knew what kind of error you are getting.
Can't you make a ss of it?
0 Sid wadhwa · October 6, 2015
means I would not have said error its kind of , just not working .........

Name:<br>
 Sid<br><br>
Email:<br>
 <img src="generate.php?id=1" />

as in index.php I have put this code and id-1 email in database is [b]example@example.com[/b] but it is not showing image of this email rather showing -> a footage means when image is wrongly uploaded we get a blank output with its sign ! .. r u getting it ? just you can say I am not getting email's footage !

nd the code I have written in another file is :

<?php
 header('content-type: image/jpeg');
 
 mysql_connect('localhost','root','');
 mysql_select_db('a_database');
 
 if(isset($_GET['id'])){
  $id = $_GET['id'];
  $query_run = mysql_query("SELECT `email` FROM `users` WHERE `id`='".mysql_real_escape_string($id)."'");
  if(mysql_num_rows($query_run)>0){
   $query_result = mysql_result($query_run, 0, 'email');
  }
  else{
   echo "ID not found.";
  }
 }
 else{
  $email = "No email address.";
 }
 
 $email_len = strlen($email);
 
 $font_size = 4;
 
 $image_height = ImageFontHeight($font_size);
 $image_width = ImageFontWidth($font_size) * $email_len;
 
 $image = imagecreate($image_width, $image_height);
 imagecolorallocate($image, 255, 255, 255);
 $font_color = imagecolorallocate($image, 0, 0, 0);
 
 imagestring($image, $font_size, 0, 0, $email, $font_color);
 imagejpeg($image);
?>

this code is in generate.php


connected to index.php ..
u get it ?
 
0 Casper Hollemans · October 6, 2015
Since id isn't a integer(that's what i assume), you dont have tu put it between single quotes.
That's only for strings.
I think this could be the problem.

try this code and use the mysql_error() for debugging

tell me if it works :D

$query_run = mysql_query("SELECT `email` FROM `users` WHERE `id`=".mysql_real_escape_string($id)) or die(mysqli_error());
0 Alan Johnson · October 4, 2015
The number of tables in a database doesn't change how you connect to it.
  • 1

PHP

106,971 followers
About

Server-side, HTML embedded scripting language used to create dynamic Web pages.

Links
Moderators